package com.yummy.cloud.gateway.manage.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.yummy.cloud.gateway.manage.dao.model.LoadBalancerConfig;
import com.yummy.cloud.gateway.manage.dto.LoadBalancerConfigQuery;
import com.yummy.cloud.gateway.manage.service.LoadBalancerConfigService;
import com.yummy.convention.http.Response;
import com.yummy.convention.page.Pagination;

@RestController
@RequestMapping("/loadbalancer/config")
public class LoadBalancerConfigController {
	
	@Autowired
	LoadBalancerConfigService loadBalancerConfigService;

	@GetMapping("/list")
	public Response<Pagination<LoadBalancerConfig>> getLoadBalanceConfigs(LoadBalancerConfigQuery query){
		return Response.success(loadBalancerConfigService.getConfigs(query));
	}
	
	@GetMapping("/get")
	public Response<LoadBalancerConfig> getLoadBalancerConfig(String serviceId){
		return Response.success(loadBalancerConfigService.getConfig(serviceId));
	}
	
	@PostMapping("/save")
	public Response<Boolean> saveLoadBalancerConfig(@RequestBody LoadBalancerConfig config){
		return Response.success(loadBalancerConfigService.saveConfig(config));
	}
	
	@PostMapping("/create")
	public Response<Boolean> createLoadBalancerConfig(@RequestBody LoadBalancerConfig config){
		return Response.success(loadBalancerConfigService.createConfig(config));
	}
	
	@PostMapping("/update")
	public Response<Boolean> updateLoadBalancerConfig(@RequestBody LoadBalancerConfig config){
		return Response.success(loadBalancerConfigService.updateConfig(config));
	}
	
	@GetMapping("/delete")
	public Response<Boolean> deleteLoadBalancerConfig(String serviceId){
		return Response.success(loadBalancerConfigService.deleteConfig(serviceId));
	}
}
